<?php

class Schedule_Form_Header_View {
    private $month_num;
    private $year;
    private $resource_type_id;
    private $day;

    function __construct($day, $month_num, $year, $resource_type_id ) {
        $this->month_num = $month_num;
        $this->year = $year;
        $this->day = $day;
        $this->resource_type_id = $resource_type_id;
    }

    public function toString() {
        $view_wrapper = new Div_Container('id', 'schedule-form-wrapper');
        $heading = new Div_Container('id', 'View_Heading');
        $body = new Div_Container('id', 'schedule-form-body');

        $d1 = new DateTime( $this->year . '-' . $this->month_num . '-' . $this->day );
        $d1->modify( 'previous day' );
        $prev_day = explode('-', $d1->format('j-n-Y'));
        
        $d2 = new DateTime( $this->year . '-' . $this->month_num . '-' . $this->day );
        $d2->modify( 'next day' );
        $next_day = explode('-', $d2->format('j-n-Y'));
        
        
        $next_btn = '<button onclick=window.location.href=' . '\'index.php?action=schedule&day=' . $next_day[0] . '&month=' .
                $next_day[1] . '&year=' . $next_day[2]. '&resource_type_id=' . $this->resource_type_id. '\'' .
                ' type="button" name="next" id="next-btn">Next Day</button>';
        $prev_btn = '<button onclick=window.location.href=' . '\'index.php?action=schedule&day=' . $prev_day[0] . '&month=' .
                $prev_day[1] . '&year=' . $prev_day[2]. '&resource_type_id=' . $this->resource_type_id.  '\'' .
                ' type="button" name="prev" id="prev-btn">Prev Day</button>';
        
        $year_month = new Div_Container('id', 'cal_month_year');

        $monthName = date("F", mktime(0, 0, 0, $this->month_num, 10));
        $year_month->addContent($monthName . ', ' . $this->year);
        $buttons = new Div_Container('id', 'next-prev-month-btn');
        $buttons->addContent( $prev_btn . $next_btn );
        $subtitle = new Div_Container('id', 'schedule-subtitle');
        
        $day_obj = new DateTime($this->year . '-' . $this->month_num . '-' . $this->day);
        $day_text = $day_obj->format('l');
        
        $resource_type_name = ResourceTypeDB::getResourceTypeNameByID($this->resource_type_id);
        $subtitle->addContent('<p>' . $this->day . ' ' . $day_text . ' - ' . $resource_type_name . '</p>');
       // $note_div = new Div_Container('class', 'mynote');
       // $note_div->addContent('<p class="mynote">Note: .</p>');
        //$subtitle->addContent($note_div->toString());
        
        $heading->addContent($year_month->toString() . $buttons->toString());
        $body->addContent($subtitle->toString());
        
        $view_wrapper->addContent($heading->toString());
        $view_wrapper->addContent($body->toString());

        return $view_wrapper->toString();
    }

}

?>
